package cn.xuguowen.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * ClassName: MyMetaObjectHandler
 * Package: cn.xuguowen.handler
 * Description:
 *
 * @Author 徐国文
 * @Create 2023/2/19 13:52
 * @Version 1.0
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"createBy",String.class,"xuguowen");
        this.strictInsertFill(metaObject,"createTime", Date.class,new Date());
        this.strictUpdateFill(metaObject,"updateBy",String.class,"xuguowen");
        this.strictUpdateFill(metaObject,"updateTime",Date.class,new Date());
        // 逻辑删除
        this.strictInsertFill(metaObject,"deleteFlag",Integer.class,0);
        // 乐观锁插件
        this.strictInsertFill(metaObject,"version",Integer.class,0);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject,"updateBy",String.class,"xuguowen");
        this.strictUpdateFill(metaObject,"updateTime",Date.class,new Date());
    }
}
